<template>
	<view class="container container24934">

		<view class="flex flex-wrap diygw-col-24 flex-direction-column flex8-clz">

			<view class="flex flex-wrap diygw-col-24 flex-direction-column flex14-clz">
				<view v-for="(item,index) in datarows" :key="index" class="flex diygw-col-24 flex-nowrap flex15-clz"
				@click="forword(item.id)">
					<view class="flex flex-wrap diygw-col-8 flex-direction-column">
						<image src="/static/global/cat.jpg" class="response diygw-col-24 image-clz" mode="widthFix">
						</image>
					</view>
					<view class="flex diygw-col-16 flex-direction-column flex-nowrap flex17-clz">
						<view class="flex diygw-col-24 justify-center items-center flex-nowrap">
							<view class="diygw-col-9 text4-clz">{{ item.petName }} </view>
							<view class="flex diygw-col-5">
								<view class="diygw-avatar xs radius bg-none">
									<image mode="aspectFit" class="diygw-avatar-img radius"
										v-bind:src="sexChoose(item.sex)"></image>
								</view>
							</view>
							<view class="diygw-col-22"> | {{ item.age }}岁 </view>
						</view>
						<view class="flex flex-wrap diygw-col-24 flex-direction-column flex19-clz">
							<view class="diygw-col-24"> {{ contentTransform(item.remark) }} </view>
						</view>
						<view class="flex diygw-col-24 flex-nowrap">
							<view v-if="convertToBinary(item.tags)[0]==1" class="flex diygw-col-7">
								<view class="diygw-tag margin-xs xs radius-sm bg-orange">
									<text> 已绝育 </text>
								</view>
							</view>
							<view v-if="convertToBinary(item.tags)[0]==0" class="flex diygw-col-7">
								<view class="diygw-tag margin-xs xs radius-sm diygw-line-orange">
									<text> 未绝育 </text>
								</view>
							</view>
							<view v-if="convertToBinary(item.tags)[1]==1" class="flex diygw-col-7">
								<view class="diygw-tag margin-xs xs radius-sm bg-orange">
									<text> 已免疫 </text>
								</view>
							</view>
							<view v-if="convertToBinary(item.tags)[1]==0" class="flex diygw-col-7">
								<view class="diygw-tag margin-xs xs radius-sm diygw-line-orange">
									<text> 未免疫 </text>
								</view>
							</view>
							<view v-if="convertToBinary(item.tags)[2]==1" class="flex diygw-col-11">
								<view class="diygw-tag margin-xs xs radius-sm bg-orange">
									<text> 已驱虫 </text>
								</view>
							</view>
							<view v-if="convertToBinary(item.tags)[2]==0" class="flex diygw-col-11">
								<view class="diygw-tag margin-xs xs radius-sm diygw-line-orange">
									<text> 未驱虫 </text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="clearfix"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//用户全局信息
				userInfo: {},
				//页面传参
				globalOption: {},
				//自定义全局变量
				globalData: {},
				tabsDatas: [{
						text: `全部`,
						icon: ``,
						id: 0
					},
					{
						text: `狗狗`,
						icon: ``,
						id: 1
					},
					{
						text: `猫咪`,
						icon: ``,
						id: 2
					},
					{
						text: `其他`,
						icon: ``,
						id: 3
					}
				],
				tabsLeft: 0,
				tabsWidth: 0,
				tabsItemWidth: 0,
				tabsIndex: 0,
				page: 1,
				size: 10,
				datarows: [],
				count: 0,
			};
		},
		onShow() {
			this.setCurrentPage(this);
		},
		onLoad(option) {
			this.setCurrentPage(this);
			if (option) {
				this.setData({
					globalOption: this.getOption(option)
				});
			}

			this.init();
		},
		methods: {
			async init() {
				this.resultApi()
			},
			contentTransform(content) {
				const maxLength = 53; // 指定的字符数
				if (content.length <= maxLength) {
					return content; // 如果内容长度小于等于指定字符数，则直接返回原内容
				} else {
					return content.substring(0, maxLength) + '...'; // 使用 substring 方法截取指定字符数，并添加省略号
				}
			},
			forword(id) {
				uni.navigateTo({
					url: 'details?id=' + id
				})
			},
			sexChoose(sex) {
				if (sex == '男') {
					return "/static/global/male.png"
				} else if (sex == '女') {
					return "/static/global/female.png"
				}
			},
			convertToBinary(tags) {
				var binaryString = tags.toString(2); // 将数字转换为二进制字符串
				while (binaryString.length < 4) {
					binaryString = '0' + binaryString; // 在字符串前面添加零
				}
				const binaryArray = binaryString.split('').map(Number); // 将二进制字符串拆分为单个字符数组，并转换为数字数组
				return binaryArray
			},
			async resultApi(){
				const page = this.page
				const size = this.size
				const http_url = '/publisherPet/page/' + page + '/' + size
				const header={
					'content-type': 'application/json;charset=UTF-8',
					"Token":uni.getStorageSync('token')
				}
				const result = await this.$http.get(http_url,'',header)
				console.log(result)
				const code = result.code
				
				if (code == 200) {
					const data = result.data.records
					this.count = result.data.total
					this.datarows = this.datarows.concat(data)
				}
			}

		},
		onReachBottom() {
			if (this.datarows.length < this.count) {
				this.page++;
				this.getListByTypeId(this.tabsIndex - 1)
			}

		},
		onPullDownRefresh() {
			this.init()
		},
	};
</script>

<style lang="scss" scoped>
	.flex-clz {
		padding-top: 10rpx;
		border-bottom-left-radius: 12rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		border-top-right-radius: 12rpx;
		margin-right: 10rpx;
		margin-left: 10rpx;
		overflow: hidden;
		width: calc(100% - 10rpx - 10rpx) !important;
		border-top-left-radius: 12rpx;
		margin-top: 10rpx;
		border-bottom-right-radius: 12rpx;
		margin-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.flex1-clz {
		padding-top: 10rpx;
		border-bottom-left-radius: 12rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		border-top-right-radius: 12rpx;
		margin-right: 10rpx;
		margin-left: 10rpx;
		overflow: hidden;
		width: calc(100% - 10rpx - 10rpx) !important;
		border-top-left-radius: 12rpx;
		margin-top: 10rpx;
		border-bottom-right-radius: 12rpx;
		margin-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.flex4-clz {
		padding-top: 10rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.flex6-clz {
		background-color: rgba(255, 41, 116, 0.64);
		border-bottom-left-radius: 20rpx;
		overflow: hidden;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
		border-bottom-right-radius: 20rpx;
	}

	.flex9-clz {
		padding-top: 10rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.text-clz {
		color: #fff9f9;
		font-weight: bold;
		font-size: 30rpx !important;
	}

	.flex10-clz {
		padding-top: 10rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.text1-clz {
		color: #fafafa;
	}

	.flex5-clz {
		padding-top: 10rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.flex7-clz {
		background-color: #00d6b6;
		border-bottom-left-radius: 20rpx;
		overflow: hidden;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
		border-bottom-right-radius: 20rpx;
	}

	.flex11-clz {
		padding-top: 10rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.text2-clz {
		color: #ffffff;
		font-weight: bold;
		font-size: 30rpx !important;
	}

	.flex12-clz {
		padding-top: 10rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.text3-clz {
		color: #ffffff;
	}

	.flex8-clz {
		padding-top: 10rpx;
		border-bottom-left-radius: 12rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		border-top-right-radius: 12rpx;
		margin-right: 10rpx;
		margin-left: 10rpx;
		overflow: hidden;
		width: calc(100% - 10rpx - 10rpx) !important;
		border-top-left-radius: 12rpx;
		margin-top: 10rpx;
		border-bottom-right-radius: 12rpx;
		margin-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.flex14-clz {
		margin-top: 20rpx;
		padding-top: 4rpx;
		padding-left: 4rpx;
		padding-bottom: 4rpx;
		padding-right: 4rpx;
	}

	.flex15-clz {
		margin-top: 20rpx;
		border-bottom-left-radius: 12rpx;
		overflow: hidden;
		border-top-left-radius: 12rpx;
		border-top-right-radius: 12rpx;
		border-bottom-right-radius: 12rpx;
	}

	.flex17-clz {
		margin-left: 20rpx;
	}

	.image-clz {
		border-bottom-left-radius: 12rpx;
		overflow: hidden;
		border-top-left-radius: 12rpx;
		border-top-right-radius: 12rpx;
		border-bottom-right-radius: 12rpx;
	}

	.flex21-clz {
		padding-top: 10rpx;
		border-bottom-left-radius: 12rpx;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		border-top-right-radius: 12rpx;
		margin-right: 10rpx;
		margin-left: 10rpx;
		overflow: hidden;
		width: calc(100% - 10rpx - 10rpx) !important;
		border-top-left-radius: 12rpx;
		margin-top: 10rpx;
		border-bottom-right-radius: 12rpx;
		margin-bottom: 10rpx;
		padding-right: 10rpx;
	}

	.container24934 {
		padding-left: 0px;
		padding-right: 0px;
	}

	.flex19-clz {
		margin-left: 10rpx;
		flex-shrink: 0;
		width: calc(100% - 10rpx - 10rpx) !important;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		height: 100rpx !important;
		margin-right: 10rpx;
	}

	.text4-clz {
		font-weight: bold;
		font-size: 28rpx !important;
	}

	.tabs-item-title.cur {
		color: #FFA500 !important;
		font-size: calc(4px + 14px) !important;
	}

	.container24934 {}
</style>